/*
using System;
using System.Collections;
using System.Drawing;
using Geometry;
using FIRADriverLibrary;
using AGHFiraPlayer;

namespace AGHFiraPlayer
{
	/// <summary>
	/// 
	/// </summary>
	public class TheCoachOf2
	{
		private const double robotDiameter = 0.1;

		// values used by all methods; for debug as well
		public Point2D kickingPoint;
		public double robotBallDistance;
		public double eta;

		public RobotController defender;
		public RobotController attacker;

		private ArrayList oponents;

		private FIRADriver firaDriver;
		private RectangleF pitchArea;
		private double goalWidth;

		private double goalStartY, goalEndY;
		private Point2D target;
		private Point2D home;


		private GameState gameState = GameState.Off;
		public GameState GameState 
		{
			get { return gameState; }
			set {gameState = value; }
		}


		public TheCoachOf2(FIRADriver firaDriver, RectangleF pitchArea, double goalWidh)
		{
			this.pitchArea = pitchArea;
			this.goalWidth = goalWidh;
			this.firaDriver = firaDriver;
			this.oponents = new ArrayList();
			foreach (FIRARobotState robot in firaDriver.firaRobots)
			{
				if (robot.owned)
				{
					if (defender == null)
						defender = new RobotController(robot);
					else if (attacker == null)
						attacker = new RobotController(robot);
				}
				else 
					oponents.Add(robot);
			}
			if (attacker == null)
				throw new Exception("Too few robots owned - cannot initialize TheCoachOf3");

			goalStartY = pitchArea.Top + pitchArea.Height / 2 - goalWidh / 2 ;
			goalEndY = goalStartY + goalWidh ;

			target = new Point2D(pitchArea.Right,  pitchArea.Top +  pitchArea.Height / 2);
			home = new Point2D(pitchArea.Left,  pitchArea.Top +  pitchArea.Height / 2);

			defender.startupPosition = new Point2D(pitchArea.Left + pitchArea.Width/2 - robotDiameter * 2, pitchArea.Top + pitchArea.Height / 2 - robotDiameter);
			attacker.startupPosition = new Point2D(pitchArea.Left +  pitchArea.Width/4, pitchArea.Top + pitchArea.Height / 2 + robotDiameter);

		}

		public void Refresh()
		{
			if (gameState == GameState.Off)
			{
				defender.Stop();
				attacker.Stop();
			}

			if (gameState == GameState.StartupPositions)
			{
				double distance = defender.Position.GetDistance(defender.startupPosition);
				if (distance > robotDiameter)
                    ;//commened in order to compile project
					//PotencialDriver.DriveETA(defender, defender.startupPosition.x, defender.startupPosition.y, distance / PotencialDriver.tinyVelocity);
				else 
					defender.Stop();
				distance = attacker.Position.GetDistance(attacker.startupPosition);
				if (distance > robotDiameter)
                    ;//commened in order to compile project
					//PotencialDriver.DriveETA(attacker, attacker.startupPosition.x, attacker.startupPosition.y, distance / PotencialDriver.tinyVelocity);
				else 
					attacker.Stop();
			}
		
			if (gameState == GameState.Play)
			{
				if (IsClearKick(attacker))
				{
					Kick(attacker);
					DefensivePosition(defender);
					attacker.main = true;
					defender.main = false;
				}
				else if (IsClearKick(defender))
				{
					Kick(defender);
					OffensivePosition(attacker);
					attacker.main = false;
					defender.main = true;
				}
				else
				{
					if (FillKickingPoint(attacker) < FillKickingPoint(defender))
					{
						attacker.main = true;
						defender.main = false;
						KickingPosition(attacker);
						DefensivePosition(defender);
					}
					else
					{
						attacker.main = false;
						defender.main = true;
						KickingPosition(defender);
						SupportPosition(attacker);
					}
				}
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="robotController"></param>
		/// <returns>estimated time to a kick</returns>
		private double FillKickingPoint(RobotController robotController)
		{
			Vector2D ballRobotVector = new Vector2D(robotController.robotState.x - firaDriver.ballX, robotController.robotState.y - firaDriver.ballY);
			double angleBallRobot = Vector2D.AngleBetween(
				Predicator.V,
				ballRobotVector
				);
			
			double real_eta = ballRobotVector.Length / (PotencialDriver.maxVelocity + Predicator.V.Length * Math.Cos(angleBallRobot));
			if (real_eta <= 0 || real_eta > pitchArea.Width / PotencialDriver.maxVelocity)
				real_eta =  pitchArea.Width / PotencialDriver.maxVelocity;
			real_eta *= 1 + 0.1 * Math.Abs( Vector2D.AngleBetween( robotController.VelocityVersor, Predicator.V));
			kickingPoint = Predicator.GetBallPosition(real_eta);
			robotBallDistance = kickingPoint.GetDistance(robotController.robotState.x, robotController.robotState.y);
			eta =  robotBallDistance / PotencialDriver.maxVelocity;
			return real_eta;			


			//			robotBallDistance = robotController.Position.GetDistance(firaDriver.ballX, firaDriver.ballY);
			//			eta = robotBallDistance / PotencialDriver.maxVelocity;
			//			kickingPoint = Predicator.GetBallPosition(eta);
			//			robotBallDistance = (robotBallDistance + kickingPoint.GetDistance(robotController.robotState.x, robotController.robotState.y) ) / 2;
			//			eta = robotBallDistance / PotencialDriver.maxVelocity;
			//			kickingPoint = Predicator.GetBallPosition(eta);
			//			return kickingPoint.GetDistance(robotController.robotState.x, robotController.robotState.y);
		}


		private bool IsClearKick(RobotController robotController)
		{
			//estimate position
			FillKickingPoint(robotController);

			//check alignment
			if (robotController.robotState.x > kickingPoint.x)
				return false;

			//check distance
			if (robotBallDistance > robotDiameter * 3)
				return false;

			//check obstacles - oponents only - if cooper is closer, he will be asked to kick
			double minX = Math.Min(robotController.robotState.x,kickingPoint.x);
			double minY = Math.Min(robotController.robotState.y,kickingPoint.y);
			double maxX = Math.Max(robotController.robotState.x,kickingPoint.x);
			double maxY = Math.Max(robotController.robotState.y,kickingPoint.y);
			foreach (FIRARobotState obstacleRobot in oponents)
			{
				if (obstacleRobot.x > minX  && obstacleRobot.x < maxX &&
					obstacleRobot.y > minY  && obstacleRobot.y < maxY )
				{
					return false;
				}
			}
			return true;
		}

		private void Kick(RobotController robotController)
		{
			FillKickingPoint(robotController);

			Vector2D ballTargetVector = new Vector2D(target.x - kickingPoint.x, target.y - kickingPoint.y);
			Vector2D robotBallVector = new Vector2D(kickingPoint.x - robotController.robotState.x, kickingPoint.y - robotController.robotState.y);

			robotBallVector.Rotate(Vector2D.AngleBetween(ballTargetVector, robotBallVector) * 0.7);

			kickingPoint.x = robotController.robotState.x + robotBallVector.X;
			kickingPoint.y = robotController.robotState.y + robotBallVector.Y;

			if (kickingPoint.x < pitchArea.Left)
				kickingPoint.x = pitchArea.Left + 0.03;
			if (kickingPoint.x > pitchArea.Right)
				kickingPoint.x = pitchArea.Right - 0.03;
			if (kickingPoint.y < pitchArea.Top)
				kickingPoint.y = pitchArea.Top + 0.03;
			if (kickingPoint.y > pitchArea.Bottom)
				kickingPoint.y = pitchArea.Bottom - 0.03;

            ;//commened in order to compile project
			//PotencialDriver.DriveETA(robotController, kickingPoint.x, kickingPoint.y, eta);

			//super kick
			//off
//			if (robotBallVector.Length < robotDiameter)
//			{
//				if (robotController.robotState.leftSpeed > robotController.robotState.rightSpeed)
//				{
//					robotController.robotState.rightSpeed /= 2;
//					robotController.robotState.leftSpeed *= 2;
//				}
//				else
//				{
//					robotController.robotState.leftSpeed /= 2;
//					robotController.robotState.rightSpeed *= 2;
//				}
//			}
		}

		private void KickingPosition(RobotController robotController)
		{
			FillKickingPoint(robotController);

			if ((robotController.robotState.y > kickingPoint.y || kickingPoint.y - 2 * robotDiameter < pitchArea.Top) && kickingPoint.y + 2 * robotDiameter < pitchArea.Bottom)
				kickingPoint.y += 2 * robotDiameter;
			else
				kickingPoint.y -= 2 * robotDiameter;

			kickingPoint.x -= 2 * robotDiameter;
			if (kickingPoint.x < pitchArea.Left)
				kickingPoint.x = pitchArea.Left + 0.03;

			eta = kickingPoint.GetDistance(robotController.robotState.x, robotController.robotState.y) / PotencialDriver.maxVelocity;

            ;//commened in order to compile project
			//PotencialDriver.DriveETA(robotController, kickingPoint.x, kickingPoint.y, eta);
		}

		private void DefensivePosition(RobotController robotController)
		{
//			robotController.Stop();
//			return;

			kickingPoint.x = firaDriver.ballX;
			kickingPoint.y = firaDriver.ballY;

			kickingPoint.x = kickingPoint.x / 2;
			kickingPoint.y = (kickingPoint.y + target.y) / 2;

			eta = kickingPoint.GetDistance(robotController.robotState.x, robotController.robotState.y) / PotencialDriver.maxVelocity;

            ;//commened in order to compile project
			//PotencialDriver.DriveETA(robotController, kickingPoint.x, kickingPoint.y, eta);
		}

		private void OffensivePosition(RobotController robotController)
		{
//			robotController.Stop();
//			return;
//
			kickingPoint.x = firaDriver.ballX;
			kickingPoint.y = firaDriver.ballY;

			kickingPoint.x = (kickingPoint.x + target.x) / 2 - 4 * robotDiameter;

			if (kickingPoint.y > target.y)
				kickingPoint.y = target.y - goalWidth;
			else
				kickingPoint.y =  target.y + goalWidth;

			eta = kickingPoint.GetDistance(robotController.robotState.x, robotController.robotState.y) / PotencialDriver.maxVelocity;

            ;//commened in order to compile project
			//PotencialDriver.DriveETA(robotController, kickingPoint.x, kickingPoint.y, eta);
		}

		private void SupportPosition(RobotController robotController)
		{
//			robotController.Stop();
//			return;

			kickingPoint.x = firaDriver.ballX;
			kickingPoint.y = firaDriver.ballY;

			if (kickingPoint.y > target.y)
				kickingPoint.y /= 2;
			else
				kickingPoint.y += (pitchArea.Height - kickingPoint.y) / 2;

			eta = kickingPoint.GetDistance(robotController.robotState.x, robotController.robotState.y) / PotencialDriver.maxVelocity;

            ;//commened in order to compile project
			//PotencialDriver.DriveETA(robotController, kickingPoint.x, kickingPoint.y, eta);

		}


	}
}
*/